import { Page } from './types'

const routesBuild: any = {
  path: '/',
  component: () => import('@/layout/LayoutLv2Front.vue'),
  name: 'LayoutLv2Front',
  children: []
}

// 路由自动生成
const pages = import.meta.glob('@/views-front/**/page.ts', {
  eager: true,
  import: 'default'
})
const comps = import.meta.glob('@/views-front/**/index.vue')

Object.entries(pages).forEach((el: [string, Page]) => {
  const path = el[0]
  const page = el[1]

  const compPath = path.replace('page.ts', 'index.vue')
  const fullPath = path.replace('/src/views-front', '').replace('/page.ts', '') || '/'
  // const newPath = fullPath.split('/')[fullPath.split('/').length - 1]
  const newPath = path.replace('/src/views-front/', '').replace('/page.ts', '') || '/'

  const route = {
    title: page.title,
    path: newPath,
    fullPath,
    meta: page.meta,
    component: comps[compPath]
  }

  routesBuild.children.push(route)
})

// console.log('asasd', routesBuild)

export {
  routesBuild
}
